/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { FileSystemSnapshotHierarchyVisitor, SnapshotVisitResult } from '../generator/filesystem-snapshot-visitor.js';
import { FileMetaData } from '../util/file-metadata.js';
import { FileType } from '../util/file-type.js';

import { BasicFileSnapshot } from './filesystem-snapshot.js';

/**
 * 单个文件快照
 *
 * @since 2022/9/1
 */
export class FileSnapshot extends BasicFileSnapshot {
  fileMetaData: FileMetaData;

  constructor(name: string, path: string, type: FileType, isSymbolicLink: boolean, fileMetaData: FileMetaData) {
    super(name, path, type, isSymbolicLink);
    this.fileMetaData = fileMetaData;
  }

  accept(visitor: FileSystemSnapshotHierarchyVisitor): SnapshotVisitResult {
    return visitor.visitEntry(this);
  }

  *walk(): IterableIterator<BasicFileSnapshot> {
    yield this;
  }

  equals(other: BasicFileSnapshot): boolean {
    if (!(other instanceof FileSnapshot)) {
      return false;
    }
    return super.isHashEquals(other);
  }
}
